import RequestHttp from '@/utils/http'
import {
  SearchParams,
  ListResult,
  RoleItem,
  RoleIdParams,
  RoleStateParams,
  RoleParams,
  RoleVoList,
  MenuIdList,
  AssignPermissionsParams,
} from './model/roleModel'

enum Api {
  index = '/api/sysRole/index',
  store = '/api/sysRole/store',
  show = '/api/sysRole/show',
  update = '/api/sysRole/update',
  state = '/api/sysRole/state',
  destroy = '/api/sysRole/destroy',
  getMenuId = '/api/sysRole/getRoleMenuIdByRoleId',
  assignPermissions = '/api/sysRole/assignPermissions',
  getVolist = '/api/sysRole/vo/list',
}

export const getList = (params?: SearchParams) => {
  return RequestHttp.get<ListResult>(Api.index, params)
}

export const store = (params: RoleParams) => {
  return RequestHttp.post<boolean>(Api.store, params)
}

export const show = (params: RoleIdParams) => {
  return RequestHttp.get<RoleItem>(Api.show, params)
}

export const update = (params: RoleParams) => {
  return RequestHttp.put<boolean>(Api.update, params)
}

export const state = (params: RoleStateParams) => {
  return RequestHttp.put<boolean>(Api.state, params)
}

export const destroy = (params: RoleIdParams) => {
  return RequestHttp.delete<boolean>(Api.destroy, params)
}

export const getMenuId = (params: RoleIdParams) => {
  return RequestHttp.get<MenuIdList[]>(Api.getMenuId, params)
}

export const assignPermissions = (params: AssignPermissionsParams) => {
  return RequestHttp.put<boolean>(Api.assignPermissions, params)
}

export const getVolist = () => {
  return RequestHttp.get<RoleVoList[]>(Api.getVolist)
}
